package com.thread;

public class SaleTicket extends Thread{

	private int ticket=50;
	int i=0;
	int j=0;
	
	public synchronized void sale(){
		if(ticket>0){
			i++;
			System.out.println(Thread.currentThread().getName()+":当前卖出第"+i+"票,还剩下"+--ticket+"票");
		 }
	}
	
	public void method(){
		System.out.println(Thread.currentThread().getName()+":不是同步代码块,"+j);
		j++;
	}
	
	@Override
	public void run() {
		while(ticket>0){
			sale();
			method();
			try {
				sleep(500);
			} catch (InterruptedException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			}
		}	
		
		
	}
	
}
